﻿
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;

namespace Platformer1
{
    class Spark : Fireball
    {
     

        public Spark()
        {
        }

        /// <summary>
        /// Constructs a new powerup.
        /// </summary>
        public Spark(Level level, Vector2 position, SpriteEffects inflip)
        {
            this.level = level;
            this.position = position;
            this.flip = inflip;

            LoadContent();
        }

        /// <summary>
        /// Loads the powerup texture and collected sound.
        /// </summary>
        public override void LoadContent()
        {
            texture = Level.Content.Load<Texture2D>("Sprites/Spark");
            origin = new Vector2(texture.Width - 16, texture.Height / 2.0f);
            mymovementanimation = new Animation(texture, .01f, true);
            fball = new AnimationPlayer();
            //collectedSound = Level.Content.Load<SoundEffect>("Sounds/PowerUp");
        }

        public override void Update(GameTime gameTime)
        {
            fElapsed += (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (fElapsed > fUpdateInterval)
            {
                duration--;
            
               
                if (duration <= 0)
                {
                    bActive = false;
                }

            }

        //fElapsed += (float)gameTime.ElapsedGameTime.TotalSeconds;
        //if (fElapsed > fUpdateInterval)
        //{
        //    fElapsed = 0f;
        //    //if (iFacing == 0)
        //    //{
        //        iX += iSpeed;
        //    //}
        //    //    iX -= iSpeed;
        //    //}

        //    // If the bullet has moved off of the screen,
        //    // set it to inactive
        //    if ((iX > 1280) || (iX < 0))
        //    {
        //        bActive = false;
        //    }
        //}
        }

        /// <summary>
        /// Called when this powerup has been collected by a player and removed from the level.
        /// </summary>
        /// <param name="collectedBy">
        /// The player who collected this powerup. Although currently not used, this parameter would be
        /// useful for creating special powerup powerups. For example, a powerup could make the player invincible.
        /// </param>
        /*public void OnCollected(Player collectedBy)
        {
            collectedSound.Play();
        }*/

        /// <summary>
        /// Draws a powerup in the appropriate color.
        /// </summary>
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (bActive)
            {
                //spriteBatch.Draw(, new Vector2 (position.X, position.Y), Color.White);
                fball.PlayAnimation(mymovementanimation);
                fball.Draw(gameTime, spriteBatch, position, flip);
            }
        }
    }
}
